1 module dlangui_bearlibterminal.window;
2 
3 import dlangui;
4 
5 class BearLibWindow : Window
6 {
7     import BearLibTerminal: BT = terminal;
8 
9     private bool needRedraw = true;
10 
11     this(dstring caption)
12     {
13         windowOrContentResizeMode = WindowOrContentResizeMode.shrinkWidgets;
14         super();
15 
16         BT.open(caption.to!string);
17         BT.set("window.resizeable=true");
18         BT.set("input.filter={keyboard+, mouse+}");
19 
20         // set background color:
21         {
22             BT.bkcolor(backgroundColor);
23             BT.clear();
24             BT.refresh();
25         }
26 
27         updateDlanguiWindowSize();
28 
29         //FIXME: why this is need here?
30         updateWindowOrContentSize();
31     }
32 
33     ~this()
34     {
35         close();
36     }
37 
38     package void updateDlanguiWindowSize()
39     {
40         with(BT)
41         {
42             onResize(
43                 state(keycode.width),
44                 state(keycode.height)
45             );
46         }
47     }
48 
49     void redrawIfNeed()
50     {
51         import dlangui_bearlibterminal.drawbuf;
52 
53         if(needRedraw == true)
54         {
55             BT.clear();
56             BearLibDrawBuf buf = new BearLibDrawBuf(width, height);
57             onDraw(buf);
58             BT.refresh();
59             destroy(buf);
60 
61             needRedraw = false;
62         }
63     }
64 
65     override:
66 
67     void close()
68     {
69         BT.close();
70     }
71 
72     /// Displays window at the first time
73     void show()
74     {
75         import dlangui.widgets.widget;
76 
77         assert(needRedraw);
78 
79         if(mainWidget !is null)
80             redrawIfNeed();
81     }
82 
83     dstring windowCaption() @property
84     {
85         return BT.get("window.title", "default_value").to!dstring;
86     }
87 
88     void windowCaption(dstring caption) @property
89     {
90         BT.setf("window.title=%s", caption);
91     }
92 
93     void windowIcon(DrawBufRef icon) @property
94     {
95         assert(false, "Isn't implemented");
96     }
97 
98     void invalidate()
99     {
100         needRedraw = true;
101     }
102 }